package com.xy.biz.xd.controller;

import com.xy.biz.xd.domain.req.ApplyDocumentFlowDropRequest;
import com.xy.biz.xd.domain.req.ReleaseDocumentFlowNewRequest;
import com.xy.biz.xd.service.DocumentFlowBorrowAndPrintAndDropService;
import com.xy.biz.xd.service.DocumentFlowDropService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "文档流程服务-废弃流程")
@Slf4j
@RequestMapping("/api/xd/document_flow_drop")
@RestController
public class DocumentFlowDropController extends AbstractDocumentFlowBorrowAndPrintAndDropController {

    @Autowired
    private DocumentFlowDropService documentFlowDropService;

    @Resource(name = "documentFlowBorrowServiceImpl")
    @Override
    protected void setDocumentFlowBorrowAndPrintAndDropService(DocumentFlowBorrowAndPrintAndDropService documentFlowBorrowAndPrintAndDropService) {
        this.documentFlowBorrowAndPrintAndDropService = documentFlowBorrowAndPrintAndDropService;
    }

    @ApiOperation("申请")
    @PostMapping(value = "/apply")
    public Result<?> applyDocumentFlow(@RequestBody ApplyDocumentFlowDropRequest request) {
        return documentFlowDropService.saveDocumentFlow(request);
    }

    @ApiOperation("放行")
    @Validatable(groups = {UpdateChecks.class})
    @PostMapping(value = "/release")
    public Result<?> releaseDocumentFlow(@RequestBody ReleaseDocumentFlowNewRequest request) {
        return documentFlowDropService.releaseDocumentFlow(request);
    }
}
